﻿using LD.Host;
using LD.Host.Properties;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD.Common
{
    public class Language
    {
        private static LanguageType lang;
        public static void Init()
        {
            rm = new ResourceManager(typeof(Resources));
            lang = (LanguageType)Enum.Parse(typeof(LanguageType), AppSettingHelper.GetConfigValue("Language") ?? "中文");
            Change(lang);
        }
        public static void Change(LanguageType lanuguage)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(lanuguage == LanguageType.中文 ? "zh" : "en");
            if (!lang.Equals(lanuguage))
                AppSettingHelper.SetConfigValue("Language", lanuguage.ToString());

            PubSub.Hub.Default.PublishAsync(lanuguage);
        }
        private static ResourceManager rm;
        public static string GetString(string text)
        {
            return rm.GetString(text);
        }
    }
}
